package com.axonactive.service;

import com.axonactive.entity.Book;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

@Stateless
public class BookService {
    @Inject
    private EntityManager entityManager;

    public BookService() {
    }

    public List<Book> getBooks() {
        Query query = entityManager.createQuery("SELECT b FROM Book b");
        return query.getResultList();
    }

    public void add(Book newBook) {
        entityManager.getTransaction().begin();
        entityManager.persist(newBook);
        entityManager.getTransaction().commit();
    }
}
